package com.shengchang.hu.supervision.UI;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;


/**
 * Created by Administrator on 2018/8/14 0014.
 */

public class BaseActivity extends AppCompatActivity {
    public static String MODULE_FLAG = "module_flag";
    public static int module_flag = 0;
    public static int DEVICE_MODEL = 0;
    private Handler mhanlder;
    private ProgressDialog mProgressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        module_flag = getIntent().getIntExtra(MODULE_FLAG, 8);

    }
    protected void handleStateMessage(Message message) {}
    /** handler */
    protected Handler getHandler() {
        if (mhanlder == null) {
            mhanlder = new Handler() {
                public void handleMessage(Message msg) {
                    handleStateMessage(msg);
                }
            };
        }
        return mhanlder;
    }
    protected void sendMessage(int what, Object obj) {
        Message message = new Message();
        message.what = what;
        message.obj = obj;
        getHandler().sendMessage(message);
    }



    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {


        super.onDestroy();
    }
    public void dismissProgressDialog()
    {
        if ((this.mProgressDialog != null) && (this.mProgressDialog.isShowing())) {
            this.mProgressDialog.cancel();
        }
    }

    public void showLongToast(String paramString)
    {
        if (!isFinishing()) {
            Toast.makeText(this, paramString, Toast.LENGTH_LONG).show();
        }
    }

    public void showProgressDialog()
    {
        showProgressDialog("", "加载中...", true);
    }

    public void showProgressDialog(String paramString1, String paramString2, boolean paramBoolean)
    {
        if (this.mProgressDialog == null) {
            this.mProgressDialog = new ProgressDialog(this);
        }
        this.mProgressDialog.setTitle(paramString1);
        this.mProgressDialog.setCancelable(paramBoolean);
        this.mProgressDialog.setMessage(paramString2);
        if (!isFinishing()) {
            this.mProgressDialog.show();
        }
    }

    public void showShortToast(String paramString)
    {
        if (!isFinishing()) {
            Toast.makeText(this, paramString, Toast.LENGTH_SHORT).show();
        }
    }

    public void showTipDialog(String paramString)
    {
        showTipDialog(paramString, null);
    }

    public void showTipDialog(String paramString, DialogInterface.OnClickListener paramOnClickListener)
    {
        showTipDialog(paramString, true, paramOnClickListener);
    }

    public void showTipDialog(String paramString, boolean paramBoolean, DialogInterface.OnClickListener paramOnClickListener)
    {
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
        localBuilder.setTitle("提示");
        localBuilder.setMessage(paramString);
        localBuilder.setCancelable(paramBoolean);
        localBuilder.setPositiveButton("确定", paramOnClickListener);
        localBuilder.create().show();
    }
}
